version: '3'
services:
  nginx:
    image: maplegend/mof-nginx:master
    networks:
      - main
    depends_on:
      - web
      - distributor
    ports:
      - 80:80
      - 443:443
      - 9001:9001
      - 4321:4321

  web:
    env_file:
      - ./service.env
      - ./web.env
      - ./db.env
      - ./secret.env
    image: rg.nl-ams.scw.cloud/minuteoffame/minute-of-fame:master
    command: /bin/sh -c "python manage.py migrate && python manage.py createcachetable && python manage.py runserver 0.0.0.0:8000"
    restart: always
    hostname: web
    environment:
      - RHOST=redis
      - NODE_ENV=production
    networks:
      - main
    depends_on:
      - db

  distributor:
    restart: always
    env_file:
      - ./service.env
      - ./secret.env
    image: rg.nl-ams.scw.cloud/minuteoffame/websocket-distributor:master
    hostname: distributor
    networks:
      - main
    depends_on:
      - web

  chat:
    restart: always
    env_file:
      - ./service.env
    image: rg.nl-ams.scw.cloud/minuteoffame/mof-chat:master
    hostname: chat
    networks:
      - main
    depends_on:
      - distributor

  queue:
    restart: always
    env_file:
      - ./service.env
    image: rg.nl-ams.scw.cloud/minuteoffame/mof-queue:master
    hostname: queue
    networks:
      - main
    depends_on:
      - distributor

  poll:
    restart: always
    env_file:
      - ./service.env
    image: rg.nl-ams.scw.cloud/minuteoffame/mof-poll:master
    hostname: chat
    networks:
      - main
    depends_on:
      - distributor

  multi_connection:
    image: maplegend/multi_connection:master
    command: node server --port 9001
    restart: always
    hostname: multi_connection
    networks:
      - main

  db:
    env_file:
      - ./db.env
    image: postgres
    restart: always
    hostname: db
    networks:
      - main
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 10s
      timeout: 5s
      retries: 5
    volumes:
      - ./db_data:/var/lib/postgresql/

  kurento:
    hostname: kurento
    image: maplegend/kurento:latest
    restart: always
    network_mode: host
    environment:
      - KMS_STUN_IP=51.15.91.233
      - KMS_STUN_PORT=3478
      - KMS_MIN_PORT=40000
      - KMS_MAX_PORT=50000
      #- KMS_TURN_URL=username:password@51.15.64.125:3478
      #- KMS_EXTERNAL_ADDRESS=51.15.64.125
      #- KMS_TURN_URL=username:password@51.15.64.125:3478
    volumes:
      - ./recs:/recs
      - ./tst.mp4:/tst.mp4
    depends_on:
      - coturn

  coturn:
    image: instrumentisto/coturn
    network_mode: host
    restart: always
    volumes:
      - ${PWD}/turnserver.conf:/etc/turnserver.conf
      - /etc/letsencrypt/live/fame.savink.in:/usr/local/etc

  stream:
    env_file:
      - ./service.env
    image: rg.nl-ams.scw.cloud/minuteoffame/mof-stream:master
    hostname: stream
    environment:
      - KMS_URL=ws://192.168.0.1:8888/kurento
    networks:
      - main
      - dockernet
    depends_on:
      - kurento
      - distributor


networks:
  main:
  dockernet:
    external: true
